package org.come.thread;

import java.util.Map;
import com.tool.image.ManimgAttribute;
import come.tool.Fighting.RandomCreepsMovePath;
import java.math.BigDecimal;
import come.tool.Fighting.CreepsMovePath;
import java.util.List;
import org.come.bean.MapMonsterBean;
import org.come.until.AccessTeamInfoUntil;
import org.come.bean.PathPoint;
import java.util.ArrayList;
import java.util.HashMap;
import com.tool.image.ImageMixDeal;

public class LoadYeguaiRunnable implements Runnable {
    private String monster;

    public LoadYeguaiRunnable(final String monster) {
        this.monster = monster;
    }

    @Override
    public void run() {
        upMonster(this.monster, true);
    }

    public static void upMonster(String monster, final boolean is) {
        if (is) {
            ImageMixDeal.mapMonsterlist.clear();
        }
        if (monster == null || monster.equals("")) {
            return;
        }
        Map<String, List<PathPoint>> pointMap = null;
        if (monster.startsWith("M")) {
            final int path = monster.indexOf("|");
            if (path == -1) {
                return;
            }
            pointMap = (Map<String, List<PathPoint>>)new HashMap();
            final String[] v = monster.substring(1, path).split("#");
            for (int i = 0; i < v.length; ++i) {
                final String[] vs = v[i].split("\\^");
                final List<PathPoint> points = (List<PathPoint>)new ArrayList();
                int j = 1;
                while (j + 1 < vs.length) {
                    final PathPoint point = new PathPoint(Integer.parseInt(vs[j++]), Integer.parseInt(vs[j++]));
                    points.add(point);
                }
                pointMap.put(vs[0], points);
            }
            monster = monster.substring(path + 1);
        }
        final String[] v2 = monster.split("\\|");
        for (String s : v2) {
            final String[] vs2 = s.split("#");
            String name = null;
            String robotTitle = null;
            String titleSkin = null;
            String[] names = null;
            final int id = Integer.parseInt(vs2[0]);
            String[] infos = vs2[1].split("\\$");
            for (String info : infos) {
                if (info.startsWith("robotTitle=")) {
                    robotTitle = info.split("=")[1];
                } else if (info.startsWith("titleSkin=")) {
                    titleSkin = info.split("=")[1];
                } else {
                    name = infos[0];
                    names = AccessTeamInfoUntil.getss(name);
                }
            }

            final int robottype = Integer.parseInt(vs2[3]);
            Label_0875:
            for (int l = 4; l < vs2.length; ++l) {
                final String[] vss = vs2[l].split("\\^");
                if (vss.length >= 3) {
                    final int I = Integer.parseInt(vss[0]);
                    final MapMonsterBean bean = new MapMonsterBean();
                    bean.setRobotid(Integer.valueOf(id));
                    bean.setRobotname(name);
                    bean.setRobotTitle(robotTitle);
                    bean.setTitleSkin(titleSkin);
                    bean.setRobotskin(vs2[2]);
                    bean.setRobottype(robottype);
                    bean.setI(Integer.valueOf(I));
                    bean.setX(Integer.valueOf(Integer.parseInt(vss[1])));
                    bean.setY(Integer.valueOf(Integer.parseInt(vss[2])));
                    bean.setType(0);
                    for (int m = 3; m < vss.length; ++m) {
                        if (vss[m].startsWith("S")) {
                            bean.setType(Integer.parseInt(vss[m].substring(1)));
                            if (bean.getType() == 2) {
                                continue Label_0875;
                            }
                        } else if (vss[m].startsWith("L")) {
                            if (pointMap != null) {
                                final int HPath = vss[m].indexOf(",");
                                if (HPath != -1) {
                                    final List<PathPoint> points2 = (List<PathPoint>)pointMap.get(vss[m].substring(1, HPath));
                                    if (points2 != null) {
                                        final CreepsMovePath movePath = new CreepsMovePath(bean.getX().intValue(), bean.getY().intValue(), Integer.parseInt(vss[m].substring(HPath + 1)), points2);
                                        bean.setMovePath(movePath);
                                    }
                                }
                            }
                        } else if (vss[m].startsWith("H")) {
                            final int HPath = vss[m].indexOf(",");
                            if (HPath != -1) {
                                final int x = Integer.parseInt(vss[m].substring(1, HPath));//怪物移动速度
                                final int y = Integer.parseInt(vss[m].substring(HPath + 1));
                                if (bean.getHP() != null) {
                                    bean.getHP().setX(x);
                                    bean.getHP().setY(y);
                                } else {
                                    bean.setHP(new PathPoint(x, y));
                                }
                            }
                        } else if (vss[m].startsWith("G")) {
                            final ManimgAttribute attribute = ImageMixDeal.huoquLogin(new BigDecimal(vss[m].substring(1)));
                            if (attribute != null) {
                                bean.setFollow(attribute.getName());
                            }
                        }
                    }
                    if (bean.getMovePath() == null) {
                        bean.setMovePath((CreepsMovePath) new RandomCreepsMovePath(bean.getX().intValue(), bean.getY().intValue()));
                    }
                    final ManimgAttribute attribute2 = new ManimgAttribute(bean, names);
                    if (bean.getMovePath() != null) {
                        bean.getMovePath().isMove(attribute2, 0L, 0);
                    }
                    ImageMixDeal.mapMonsterlist.add(attribute2);
                }
            }
        }
    }
}
